package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.*;
import cn.wolfcode.trip.base.query.DailyPaperQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 攻略资源控制器
 */
@RestController
@RequestMapping("dailyPaper")
public class DailyPaperController {
    @Autowired
    private IDailyPaperService dailyPaperService;

    /**
     * 查询所有攻略信息 分页
     * @return
     */
    @GetMapping
    public PageInfo query(DailyPaperQueryObject qo) {
        return dailyPaperService.query(qo);
    }

    /**
     * 查询对应用户关注的日报信息
     * @param qo
     * @return
     */
    @GetMapping("{userId}/DailyPaper")
    public PageInfo queryByUserId(DailyPaperQueryObject qo) {
        return dailyPaperService.queryByUserId(qo);
    }

    /**
     * 查询符合关键字的信息条数
     * @param qo
     * @return
     */
    @GetMapping("{keyword}/countNum")
    public int getNum(DailyPaperQueryObject qo){
        int num=dailyPaperService.selectNumByKeyword(qo);
        return num;
    }


    @GetMapping("{id}")
    public DailyPaper getDailyPaperById(@PathVariable("id")Long id){
        return dailyPaperService.getDailyPaperById(id);
    }

    /**
     * 根据用户id查询他的关注信息
     * @param uId
     * @return
     */
    @GetMapping("Collect/{uId}")
    public List getCollect (@PathVariable("uId")Long uId){
        List list=dailyPaperService.getCollect(uId);
        return list;
    }

    /**
     * 根据用户id查询他的点赞信息
     * @param uId
     * @return
     */
    @GetMapping("like/{uId}")
    public List getlike (@PathVariable("uId")Long uId){
        List list=dailyPaperService.getlike(uId);
        return list;
    }

    /**
     * 添加点赞
     * @param userId
     * @param likeId
     * @return
     */
    @PostMapping("addLike/{userId}/{likeId}")
    public JSONResult addLike(@PathVariable("userId")Long userId,
                              @PathVariable("likeId")Long likeId){
        dailyPaperService.addLike(userId,likeId);
        return new JSONResult();
    }

    /**
     * 添加收藏
     * @param userId
     * @param collectId
     * @return
     */
    @PostMapping("addCollect/{userId}/{collectId}")
    public JSONResult addCollect(@PathVariable("userId")Long userId,
                              @PathVariable("collectId")Long collectId){
        dailyPaperService.addCollect(userId,collectId);
        return new JSONResult();
    }

    /**
     * 根据用户id和日报id删除对应的点赞数据
     * @param userId
     * @param likeId
     */
    @DeleteMapping("/removeLike/{userId}/{likeId}")
    public JSONResult deleteLike(@PathVariable("userId")Long userId,@PathVariable("likeId")Long likeId){
        dailyPaperService.deleteLike(userId,likeId);
        return new JSONResult();
    }


    /**
     * 根据用户id和日报id删除对应收藏的数据
     * @param userId
     * @param CollectId
     * @return
     */
    @DeleteMapping("/removeCollect/{userId}/{collectId}")
    public JSONResult deleteCollect(@PathVariable("userId")Long userId,@PathVariable("collectId")Long CollectId){
        dailyPaperService.deleteCollect(userId,CollectId);
        return new JSONResult();
    }
}
